package com.vmusic.data;

import java.io.File;
import java.util.Date;

import org.apache.commons.io.FileUtils;

/**
 * 制作用户数据类
 *
 */
public class UserData extends MakeData{
	public static char[] chr = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
			'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
			'w', 'x', 'y', 'z' };
	public static int[] nameLength = new int[] { 4, 5, 6 };
	public static String[] citys = new String[] { "beijing", "shanghai",
			"guangzhou" };

	public static void main(String[] args) throws Exception {
		makeUserData();
	}
	
	/**
	 * 制作用户日志方法
	 * @throws Exception
	 */
	public static void makeUserData() throws Exception {
		Long times = new Date().getTime();
		String result = "";
		for (int i = 10000; i < 20000; i++) {
			result = i + "\t" + getUserName() + "\t" + r.nextInt(2) + "\t"
					+ CreateSimpleDateTimeString() + "\t" + getCity() + "\n";
			FileUtils.writeStringToFile(new File("user.txt"), result, true);
		}
		System.out.println((new Date().getTime() - times) / 1000 + "秒");
	}

	
	/**
	 * 随即城市
	 * @return
	 */
	public static String getCity() {
		return citys[r.nextInt(3)];
	}
	
	/**
	 * 随机姓名，范围4-6长度字母，首字母大写
	 * @return
	 */
	public static String getUserName() {
		StringBuffer result = new StringBuffer();
		for (int i = 0; i < nameLength[r.nextInt(3)]; i++) {
			result.append(chr[r.nextInt(26)]);
		}
		char[] array = result.toString().toCharArray();  
		array[0] -= 32;  
		return String.valueOf(array);  
	}
}
